/*
 * @lc app=leetcode id=560 lang=cpp
 *
 * [560] Subarray Sum Equals K
 */
class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        int len = nums.size();
        if (len < 1) {
            return 0;
        }

        int count = 0;
        for (int i=0; i<len; i++) {
            int sum = nums[i];
            if (sum == k) {
                count++;
            }
            for (int j=i+1; j<len; j++) {
                sum += nums[j];
                if (sum == k) {
                    count++;
                }
            }
        }
        return count;
    }
};

